//==================================================================
/// CppKazRace_Load.cpp
///
/// Created by Davide Pasca - 2010/3/30
/// See the file "license.txt" that comes with this project for
/// copyright info. 
//==================================================================

#include "stdafx.h"
#include "CppKazRace.h"

//==================================================================
void CppKazRace::load_cars()
{
	mpoRQueen1 = new sprite( "rq1.png", sprite::MIDDLE, sprite::BOTTOM );
	mpoRQueen2 = new sprite( "rq2.png", sprite::MIDDLE, sprite::BOTTOM );
	mpoRQueen3 = new sprite( "rq3.png", sprite::MIDDLE, sprite::BOTTOM );
	mpoRQueen4 = new sprite( "rq4.png", sprite::MIDDLE, sprite::BOTTOM );
	mpoStartFrame = new sprite( "start_frame.png", sprite::MIDDLE, sprite::BOTTOM, 2.0f );

	mpoF500 = new sprite( "f500_-1.png", sprite::MIDDLE, sprite::BOTTOM );
	mpoF500->add_frame( "f500_0.png" );
	mpoF500->add_frame( "f500_1.png" );

	mpoMoo = new sprite( "moo_0_-2.png", sprite::MIDDLE, sprite::BOTTOM, 2.0f );
	mpoMoo->add_frame( "moo_0_-1.png" );
	mpoMoo->add_frame( "moo_0_0.png" );
	mpoMoo->add_frame( "moo_0_1.png" );
	mpoMoo->add_frame( "moo_0_1.png" );


	mpoMyCarSptr = new sprite( "f355_0_-2.png", sprite::MIDDLE, sprite::MIDDLE );
	mpoMyCarSptr->add_frame( "f355_0_-1.png" );
	mpoMyCarSptr->add_frame( "f355_0_0.png" );
	mpoMyCarSptr->add_frame( "f355_0_1.png" );
	mpoMyCarSptr->add_frame( "f355_0_2.png" );
	mpoMyCarSptr->add_frame( "f355_-1_0.png" );
	mpoMyCarSptr->add_frame( "f355_1_0.png" );

	mpoMyCarSptr->mX = 0;
	mpoMyCarSptr->mY = 0;
	mpoMyCarSptr->mZ = 0;
}

//==================================================================
void CppKazRace::load_road()
{
	// setup road
	mpoRoad = new road( mpoXFormer.get() );  // 360

	mpoRoad->colors_set(
		color( 130, 125, 120 ),
		color( 250, 250, 250 ),
		color( 230, 230, 0 ),//20, 20, 20,
		color( 230, 230, 0 ),//220, 220, 5,
		color( 200, 190, 170 ),
		color( 160, 150, 155 ) );

	// load road sprites
	sprite *pSptr = new sprite( "beach_l.png", sprite::RIGHT, sprite::BOTTOM );
	pSptr->shadow_off();
	//mpoRoad->sprite_fill( sprt );

	sprite *rock = new sprite( "rock.png", sprite::MIDDLE, sprite::BOTTOM, 2.0f );
	rock->shadow_off();

	mpoSprites.push_back( rock );

	sprite	*r_palm			= new sprite( "palm2_r.png", sprite::MIDDLE, sprite::BOTTOM );
	sprite	*bush1			= new sprite( "bush2.png", sprite::MIDDLE, sprite::BOTTOM );
	sprite	*bb_rq1			= new sprite( "bboard_rq1.png", sprite::MIDDLE, sprite::BOTTOM );
	sprite	*pole_r			= new sprite( "pole_r.png", sprite::MIDDLE, sprite::BOTTOM );
	sprite	*pole2_r		= new sprite( "pole2_r.png", sprite::MIDDLE, sprite::BOTTOM );
	sprite	*grass_side_r	= new sprite( "grass_side_r.png", sprite::MIDDLE, sprite::BOTTOM );
	sprite	*white_house	= new sprite( "white_house.png", sprite::MIDDLE, sprite::BOTTOM, 3.0f );
	sprite	*hotel_l		= new sprite( "hotel_l.png", sprite::RIGHT, sprite::BOTTOM, 6.0f );

	mpoSprites.push_back( r_palm		);
	mpoSprites.push_back( bush1			);
	mpoSprites.push_back( bb_rq1		);
	mpoSprites.push_back( pole_r		);
	mpoSprites.push_back( pole2_r		);
	mpoSprites.push_back( grass_side_r	);
	mpoSprites.push_back( white_house	);
	mpoSprites.push_back( hotel_l		);

	grass_side_r->shadow_off();

	int lanes = 5;

	static const int L1_XOFF = -350;
	static const int L2_XOFF = -300;
	static const int R1_XOFF = 350;
	static const int R2_XOFF = 350;

	static const int L3_XOFF = -60;
	static const int R3_XOFF =  60;

	mpoRoad->sector_sprites_add( road::L3, pole_r, 300, 16, L3_XOFF+70 );
	mpoRoad->sector_sprites_add( road::R3, pole_r, 300, 16, R3_XOFF-70 );

	mpoRoad->sector_sprites_add( road::L3, pole2_r, 300, 16, L3_XOFF+70 );
	mpoRoad->sector_sprites_add( road::R3, pole2_r, 300, 16, R3_XOFF-70 );

	mpoRoad->sector_sprites_add( road::L3, pole_r, 300, 16, L3_XOFF+70 );
	mpoRoad->sector_sprites_add( road::R3, pole_r, 300, 16, R3_XOFF-70 );

	mpoRoad->sector_sprites_add( road::L3, pole2_r, 300, 16, L3_XOFF+70 );
	mpoRoad->sector_sprites_add( road::R3, pole2_r, 300, 16, R3_XOFF-70 );

	mpoRoad->sector_sprites_add( road::L3, pole2_r, 1000, 16, L3_XOFF+70 );
	mpoRoad->sector_sprites_add( road::R3, pole2_r, 1000, 16, R3_XOFF-70 );

	mpoRoad->sector_sprites_add( road::L3, pole_r, 300, 16, L3_XOFF+70 );
	mpoRoad->sector_sprites_add( road::R3, pole_r, 300, 16, R3_XOFF-70 );

	mpoRoad->sector_sprites_add( road::L3, pole2_r, 1000, 16, L3_XOFF+70 );
	mpoRoad->sector_sprites_add( road::R3, pole2_r, 1000, 16, R3_XOFF-70 );

	mpoRoad->sector_sprites_add( road::L3, pole2_r, 10, 16, L3_XOFF+70 );
	mpoRoad->sector_sprites_add( road::R3, pole2_r, 10, 16, R3_XOFF-70 );

	mpoRoad->sector_add( lanes, 0, 0, 100 );

	mpoRoad->sector_sprites_add( road::L1, r_palm, 100, 16, L1_XOFF );	// grass_side_r
	mpoRoad->sector_sprites_add( road::L2, bush1, 100, 8, L2_XOFF );
	mpoRoad->sector_sprites_add( road::R1, bush1, 100, 8, R1_XOFF );
	mpoRoad->sector_sprites_add( road::R2, white_house, 100, 16, R2_XOFF+500 );


	mpoRoad->sector_add( lanes, 0, 20, 20 );
	mpoRoad->sector_add( lanes, 0, -15, 10 );
	mpoRoad->sector_add( lanes, 0, 0, 30 );

	mpoRoad->sector_sprites_add( road::L1, bush1, 60, 8, L1_XOFF );
	mpoRoad->sector_sprites_add( road::L2, hotel_l, 60, 16, L1_XOFF );
	mpoRoad->sector_sprites_add( road::R1, white_house, 60, 16, R1_XOFF+500 );
	mpoRoad->sector_sprites_add( road::R2, bush1, 60, 8, R2_XOFF );

	mpoRoad->sector_add( lanes,  50, 0, 40 );

	mpoRoad->sector_sprites_add( road::L1, bush1, 40, 8, L1_XOFF );
	mpoRoad->sector_sprites_add( road::L2, hotel_l, 40, 16, L2_XOFF );
	mpoRoad->sector_sprites_add( road::R1, r_palm,  40, 8, R1_XOFF );
	mpoRoad->sector_sprites_add( road::R2, r_palm,  40, 8, R2_XOFF+200 );


	mpoRoad->sector_add( lanes, -70, -40, 30 );

	mpoRoad->sector_sprites_add( road::L1, r_palm, 30, 16, L1_XOFF );	// grass_side_r
	mpoRoad->sector_sprites_add( road::L2, bush1, 30, 8, L2_XOFF );
	mpoRoad->sector_sprites_add( road::R1, bb_rq1,  30, 8, R1_XOFF );
	mpoRoad->sector_sprites_add( road::R2, 30 );


	mpoRoad->sector_add( lanes, -70, 0, 60 );

	mpoRoad->sector_sprites_add( road::L1, white_house, 40, 16, L1_XOFF-500 );
	mpoRoad->sector_sprites_add( road::L2, 60 );
	mpoRoad->sector_sprites_add( road::R1, bush1, 60, 4, R1_XOFF );
	mpoRoad->sector_sprites_add( road::R2, 60 );

	mpoRoad->sector_add( lanes,  0,  40, 100 );

	mpoRoad->sector_sprites_add( road::L1, bush1, 100, 4, L1_XOFF );
	mpoRoad->sector_sprites_add( road::L2, 100 );
	mpoRoad->sector_sprites_add( road::R1, bush1, 100, 4, R1_XOFF );
	mpoRoad->sector_sprites_add( road::R2, white_house, 100, 16, R2_XOFF+1500 );

	mpoRoad->sector_add( lanes, 0, 60, 150 );

	mpoRoad->sector_sprites_add( road::L1, bush1, 150, 4, L1_XOFF );
	mpoRoad->sector_sprites_add( road::L2, 150 );
	mpoRoad->sector_sprites_add( road::R1, rock, 100, 4, R1_XOFF );
	mpoRoad->sector_sprites_add( road::R1, rock, 20, 4, R1_XOFF );
	mpoRoad->sector_sprites_add( road::R1, rock, 30, 4, R1_XOFF );
	mpoRoad->sector_sprites_add( road::R2, 150 );

	mpoRoad->sector_add( lanes, 0, -60, 100 );

	mpoRoad->sector_sprites_add( road::L1, bush1, 100, 4, L1_XOFF );
	mpoRoad->sector_sprites_add( road::L2, r_palm, 100, 16, L2_XOFF );
	mpoRoad->sector_sprites_add( road::R1, bb_rq1, 100, 8, R1_XOFF );
	mpoRoad->sector_sprites_add( road::R2, r_palm, 100, 16, R2_XOFF+400 );

	mpoRoad->sector_add( lanes, -40, 0, 150 );

	mpoRoad->sector_sprites_add( road::L1, bush1, 150, 8, L1_XOFF );
	mpoRoad->sector_sprites_add( road::L2, hotel_l, 150, 16, L2_XOFF );
	mpoRoad->sector_sprites_add( road::R1, rock,100, 4, R1_XOFF );
	mpoRoad->sector_sprites_add( road::R1, rock, 50, 4, R1_XOFF );
	mpoRoad->sector_sprites_add( road::R2, 150 );

	mpoRoad->sector_add( lanes, 0, -80, 200 );

	mpoRoad->sector_sprites_add( road::L1, bush1, 200, 8, L1_XOFF );
	mpoRoad->sector_sprites_add( road::L2, hotel_l, 200, 16, L2_XOFF );

	mpoRoad->sector_sprites_add( road::R1, r_palm, 200, 16, R1_XOFF );
	mpoRoad->sector_sprites_add( road::R2, bush1, 200, 8, R2_XOFF );

	mpoRoad->sector_add( lanes, 40, 60, 100 );

	mpoRoad->sector_sprites_add( road::L1, bush1, 100, 8, L1_XOFF );
	mpoRoad->sector_sprites_add( road::L2, 100 );
	mpoRoad->sector_sprites_add( road::R1, r_palm, 100, 8, R1_XOFF );
	mpoRoad->sector_sprites_add( road::R2, bush1, 100, 8, R2_XOFF );

	mpoRoad->sector_add( lanes, 0, -150, 400 );

	mpoRoad->sector_sprites_add( road::L1, bush1, 400, 8, L1_XOFF );
	mpoRoad->sector_sprites_add( road::L2, r_palm, 400, 16, L2_XOFF );

	mpoRoad->sector_sprites_add( road::R1, 200 );
	mpoRoad->sector_sprites_add( road::R1, bush1, 200, 8, R1_XOFF );
	mpoRoad->sector_sprites_add( road::R2, r_palm, 400, 16, R2_XOFF );

	mpoRoad->sector_add( lanes, 0, 80, 50 );
	mpoRoad->sector_add( lanes, 0, -70, 50 );

	mpoRoad->sector_sprites_add( road::L1, bush1, 100, 8, L1_XOFF );
	mpoRoad->sector_sprites_add( road::L2, bush1, 100, 16, L2_XOFF );

	mpoRoad->sector_sprites_add( road::R1, bush1, 100, 8, R1_XOFF );
	mpoRoad->sector_sprites_add( road::R2, bush1, 100, 16, R2_XOFF );

	mpoRoad->sector_add( lanes, 0, 0, 300 );
	mpoRoad->sector_add( lanes, 60, 0, 15 );
	mpoRoad->sector_add( lanes, -60, 0, 15 );
	mpoRoad->sector_add( lanes, 0, 0, 370 );

	mpoRoad->sector_sprites_add( road::L1, 700 );//bush1, 700, 8, L1_XOFF );
	mpoRoad->sector_sprites_add( road::L2, r_palm, 700, 16, L2_XOFF );

	mpoRoad->sector_sprites_add( road::R1, r_palm, 400, 8, R1_XOFF );
	mpoRoad->sector_sprites_add( road::R1, bush1, 200, 8, R1_XOFF );
	mpoRoad->sector_sprites_add( road::R1, bb_rq1, 100, 8, R1_XOFF );

	mpoRoad->sector_sprites_add( road::R2, r_palm, 400, 16, R1_XOFF+400 );
	mpoRoad->sector_sprites_add( road::R2, r_palm, 200, 16, R1_XOFF+400 );		
	mpoRoad->sector_sprites_add( road::R2, r_palm, 100, 16, R1_XOFF+400 );

	mpoRoad->sector_add( lanes, -20, 0, 100 );

	mpoRoad->sector_sprites_add( road::R1, bush1, 100, 8, R1_XOFF );
	mpoRoad->sector_sprites_add_empty( road::R2, 100 );

	mpoRoad->sector_add( lanes, -10, 60, 100 );

	mpoRoad->sector_add( lanes, 0, 0, 200 );

	mpoRoad->sector_sprites_add( road::R1, r_palm, 200, 16, R1_XOFF );
	mpoRoad->sector_sprites_add_empty( road::R2, 200 );

	mpoRoad->sector_add( lanes, 30, -40, 150 );

	mpoRoad->sector_sprites_add( road::R1, rock, 150, 4, R1_XOFF );
	mpoRoad->sector_sprites_add_empty( road::R2, 150 );

	mpoRoad->sector_add( lanes, 30, 40, 50 );

	mpoRoad->sector_sprites_add( road::R1, rock, 50, 4, R1_XOFF );
	mpoRoad->sector_sprites_add_empty( road::R2, 50 );

	mpoRoad->sector_add( lanes, 30, -40, 20 );

	mpoRoad->sector_sprites_add( road::R1, rock, 20, 4, R1_XOFF );
	mpoRoad->sector_sprites_add_empty( road::R2, 20 );

	mpoRoad->sector_add( lanes, 0, 0, 300 );

	mpoRoad->sector_sprites_add( road::R1, r_palm, 300, 8, R1_XOFF );
	mpoRoad->sector_sprites_add( road::R2, rock, 300, 8, R1_XOFF+200 );

	mpoRoad->sector_add( lanes, 0, 0, 100 );

	mpoRoad->sector_sprites_add( road::R1, r_palm, 100, 8, R1_XOFF );
	mpoRoad->sector_sprites_add( road::R2, rock, 100, 8, R1_XOFF+200 );    


	mpoRoad->x_off( 350 );
	mpoRoad->vehicles_set( mpoVehicles );
}

//==================================================================
void CppKazRace::load_stage()
{
	mpoPO->set_offset( 150, 340/2 );

	// load sky
	mpoHor->sky_picture_set( "bg_cloudy3.png" );

	load_road();

	load_cars();

	mpoSmokeSprt = new sprite( "tsmoke1.png", sprite::MIDDLE, sprite::MIDDLE );
	mpoSmokeSprt->shadow_off();
	mpoSmokeLPart = new particler( mpoXFormer.get() );
	mpoSmokeRPart = new particler( mpoXFormer.get() );

	reset_pos();
}
